import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
public class Client {
    public static void main(String[] args) throws SocketException {
        String readline = null;
        BufferedReader standard_in = null;  
        BufferedReader socket_in = null;    
        PrintWriter socket_out = null;      

        try{

            Socket socket = new Socket("127.0.0.1", 4700);
            try{
                standard_in = new BufferedReader(new InputStreamReader(System.in));
                socket_in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                socket_out = new PrintWriter(socket.getOutputStream());

                readline = standard_in.readLine();
                while(!readline.equalsIgnoreCase("bye")){
                    socket_out.println(readline);
                    socket_out.flush();
                    System.out.println("Client send data:\t"+readline);
                    System.out.println("Client accept data:\t"+socket_in.readLine());
                    readline = standard_in.readLine();
                }

            }catch(IOException E){
                E.printStackTrace();
            }

            //close resource

            standard_in.close();
            socket_in.close();
            socket_out.close();                                                                                                                                                                                                                    
            socket.close();

        }catch(UnknownHostException e){
            e.printStackTrace();
        } catch(IOException e){
            e.printStackTrace();
        }
    }

}